using NUnit.Framework;
using WWB.DisqusSharp.Model;
using WWB.DisqusSharp.Model.DisqusDTO;
using WWB.DisqusSharp.Model.DisqusService;

namespace WWB.DisqusSharp.Tests.ModelSerialization
{
    [TestFixture]
    [Category("Unit Tests")]
    public class ThreadsPayloadTest
    {
        private IDisqusServiceResult<DisqusFullBodyThread[]> resultBase;

        [TestFixtureSetUp]
        public void ArrangeAndAct()
        {
            #region json
            string json =
                "{\"message\": [{\"category\": {\"id\": 445069, \"title\": \"General\"}, \"allow_comments\": true, \"hidden\": false, \"forum\": \"438500\", \"title\": \"http://localhost/cicsite/demos/disqus\", \"url\": \"http://localhost/cicsite/demos/disqus\", \"created_at\": \"2010-08-19T15:38\", \"identifier\": [\"http://localhost/cicsite/demos/disqus\"], \"id\": \"131317088\", \"slug\": \"thread_45\"}, {\"category\": {\"id\": 445069, \"title\": \"General\"}, \"allow_comments\": true, \"hidden\": false, \"forum\": \"438500\", \"title\": \"http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d\", \"url\": \"http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d\", \"created_at\": \"2010-08-19T15:21\", \"identifier\": [\"http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d\"], \"id\": \"131312042\", \"slug\": \"thread_17\"}, {\"category\": {\"id\": 445069, \"title\": \"General\"}, \"allow_comments\": true, \"hidden\": false, \"forum\": \"438500\", \"title\": \"http://localhost/cicsite/Preview/Page/1000?key=Vb7pe53ugfQ3bLr8HbQo1VD%2bH3%2fZQewmZ0zfJwLNLWM%3d\", \"url\": \"http://localhost/cicsite/Preview/Page/1000?key=Vb7pe53ugfQ3bLr8HbQo1VD%2bH3%2fZQewmZ0zfJwLNLWM%3d\", \"created_at\": \"2010-08-12T18:16\", \"identifier\": [\"http://localhost/cicsite/Preview/Page/1000?key=Vb7pe53ugfQ3bLr8HbQo1VD%2bH3%2fZQewmZ0zfJwLNLWM%3d#\"], \"id\": \"128985216\", \"slug\": \"thread\"}], \"code\": \"ok\", \"succeeded\": true}";
            #endregion

            resultBase = new DisqusServiceResultWrapper<DisqusFullBodyThread[]>(json);
        }

        [Test]
        public void Result_is_not_null()
        {
            Assert.That(resultBase, Is.Not.Null);
        }

        [Test]
        public void Result_has_expected_scalars()
        {
            Assert.That(resultBase.Error, Is.Null);
            Assert.That(resultBase.IsSuccessful);
        }

        [Test]
        public void Result_has_some_messages()
        {
            Assert.That(resultBase.Payload, Is.Not.Null);
            Assert.That(resultBase.Payload.Length, Is.EqualTo(3));
        }

        [Test]
        public void Message_0_spot_check()
        {
            var f = resultBase.Payload[0];
            Assert.That(f.CategoryId, Is.EqualTo("445069"));
            Assert.That(f.Slug, Is.EqualTo("thread_45"));
            Assert.That(f.Id, Is.EqualTo("131317088"));
        }

        [Test]
        public void Message_1_spot_check()
        {
            var f = resultBase.Payload[1];
            Assert.That(f.CreatedAt.Minute, Is.EqualTo(21));
            Assert.That(f.CreatedAt.Hour, Is.EqualTo(15));
            Assert.That(f.Title, Is.EqualTo("http://localhost/cicsite/Preview/Page/1002?key=WvTAxsm84urxr%2btBbusUIcm4Z9u70Y9%2bQs7Kqj3OACo%3d"));
            Assert.That(f.Hidden, Is.EqualTo(false));
            Assert.That(f.Id, Is.EqualTo("131312042"));
        }

        [Test]
        public void Message_2_spot_check()
        {
            var f = resultBase.Payload[2];
            Assert.That(f.ForumId, Is.EqualTo("438500"));
            Assert.That(f.AllowComments, Is.EqualTo(true));
            Assert.That(f.Identifier[0], Is.EqualTo("http://localhost/cicsite/Preview/Page/1000?key=Vb7pe53ugfQ3bLr8HbQo1VD%2bH3%2fZQewmZ0zfJwLNLWM%3d#"));
            Assert.That(f.Id, Is.EqualTo("128985216"));
        }
    }
}